<template>
    <div id="app">
        <router-view/>
        <router-view
                name="headerBar"
                :loginType="loginType"
                :login="login"
                :urls="urls"
                @clearCookie="clear"
        ></router-view>
        <router-view name="asideNav"
                     :number="number"
                     :login="login"
                     :asideShow="asideShow"></router-view>
        <router-view name="login"
                     :urls="urls"
                     @setCookie="set">
        </router-view>
        <main>
            <router-view name="tableMain" v-for="list in asideShow" :key="list.id" v-if="list === '账号管理'" :urls="urls">
            </router-view>
            <router-view name="client" v-for="list in asideShow" :key="list.id" v-if="list === '客户管理'" :urls="urls">
            </router-view>
            <router-view name="company" :login="login" v-for="list in asideShow" :key="list.id" v-if="list === '公司管理'" :urls="urls">
            </router-view>
            <router-view name="houses" v-for="list in asideShow" :key="list.id" v-if="list === '楼盘管理'" :urls="urls">
            </router-view>
            <router-view name="finance" v-for="list in asideShow" :key="list.id" v-if="list === '财务管理'" :urls="urls">
            </router-view>
            <router-view name="finance1" v-for="list in asideShow" :key="list.id" v-if="list === '我的财务'" :urls="urls">
            </router-view>
            <router-view name="hallList" v-for="list in asideShow" :key="list.id" v-if="list === '事业部总列表'"  :urls="urls">
            </router-view>
            <router-view name="announcementManagement" :urls="urls">
            </router-view>
            <router-view name="myAnnouncement" :number="number" :urls="urls">
            </router-view>
            <router-view name="textEdit">
            </router-view>
        </main>
    </div>
</template>
<script>
    //未避免vue、layui渲染冲突，此项目先vue渲染数据
    import $ from 'jquery'
    import u from './urls.js'//请求地址文件
    export default {
        name: 'App',
        data() {
            return {
                urls: u,
                loginType: true,
                login: [],
                asideShow: [],
                token: this.getCookie('token'),
                number:0,
            }
        },
      created(){
        var loginUrl = window.location.pathname;
        var _this = this;
        for(var x in this.urls){//为urls注入token
          for(var y in this.urls[x]){
            var c = this.urls[x][y].indexOf('?') === -1?'?':'&';
            this.urls[x][y] = this.urls[x][y]+c+'token='+this.token;
          }
        }
        if (!this.getCookie('token') && loginUrl !== '/login') {
          window.location.href = '/login';
        }
        $.get(this.urls.event.use, function (res) {
          if(res.code === '400' && loginUrl !== '/login' ){
            window.location.href = '/login'
          }
          _this.login = res.login;
          _this.asideShow = res.fun;
        });
        $.get(this.urls.public.getMyAnnouncementVal,function(res){
          _this.number = res.count;
        })
    },
        computed: {

        },
        methods: {
            set: function (msg) {
                var cname = msg.split(',')[0];
                var cvalue = msg.split(',')[1];
                var exdays = msg.split(',')[2];
                // console.log(msg)
                this.setCookie(cname, cvalue, exdays)
            },
            clear: function (msg) {
                this.clearCookie(msg);
            },
            setCookie: function (cname, cvalue, exdays) {
                var d = new Date();
                d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                var expires = 'expires=' + d.toUTCString();
                document.cookie = cname + '=' + cvalue + ';' + expires;
                // console.info(document.cookie);
            },
            getCookie: function (cname) {
                var name = cname;
                var ca = document.cookie.split(';');
                // console.log(ca)
                for (var i = 0; i < ca.length; i++) {
                    var c = ca[i].split('=');
                    if ($.trim(c[0]) === name) {
                        return c[1];
                    }
                }
                return '';
            },
            clearCookie: function (cname) {
                this.setCookie(cname, '', -1);
            }
        }
    }
</script>

<style lang="less">
    @import "../static/css/style.less";

    #app {
        width: auto;
        height: 100%;
    }

    main {
        margin: 40px 0 0 180px;
        padding: 10px 35px 35px;
        /*padding-left: 35px;*/
    }

    input {
        color: @c6 !important;
    }

    /*.layui-unselect{*/
    /*border-left: 0;*/
    /*}*/
    .xm-select-parent dd {
        > .xm-cz-group {
            .pa;
            width: 140px;
            left: 0;
            right: 0;
            margin: auto;
            margin-top: 10px;
            border: none;
            .xm-cz:last-child {
                display: none !important;
            }
        }
        > .xm-cz {
            .dn;
        }
    }

    .layui-form-item .layui-form-checkbox[lay-skin=primary] {
        margin: 0;
    }
    .layui-form-pane .layui-input{
        height: 30px!important;
    }
</style>
